from django.db import models

# Create your models here.
# 会员
class users(models.Model):
    # 用户名
    name = models.CharField(max_length=50)
    # 昵称
    nickname = models.CharField(max_length=50,null=True)
    # 密码
    password = models.CharField(max_length=77)
    # 性别
    sex = models.CharField(max_length=1,choices=(('1','男'),('0','女'),('2','保密')),null=True)
    # 年龄
    age = models.IntegerField(null=True)
    # 电话号码
    phone = models.CharField(max_length=11)
    # 邮箱
    email = models.CharField(max_length=100,null=True)
    # 头像s
    Headpic = models.CharField(max_length=100,null=True)
    # 注册时间
    Rigtime = models.DateTimeField(auto_now_add=True)
    # 用户帐号状态  0:正常  1:禁用  2:逻辑删除
    status = models.IntegerField(default=0)

    class Meta:
        db_table = 'userinfo'


# 商品分类
class category(models.Model):
    # 分类名
    name = models.CharField(max_length=50)
    pid = models.IntegerField()
    path = models.CharField(max_length=20)

    class Meta:
        db_table = 'category'

# 商品模型
class goods(models.Model):
    # 商品名
    name = models.CharField(max_length=255)
    # 外键
    category_id = models.ForeignKey(to=category,to_field='id')
    # 价格
    price = models.FloatField()
    # 库存
    store = models.IntegerField()
    # 详情
    info = models.TextField()
    # 主图片
    pic_url = models.CharField(max_length=100)
    # 状态  0:新发布 1:热卖 2:下架  3:打折
    status = models.IntegerField(default=0)
    # 添加时间
    addtime = models.DateTimeField(auto_now_add=True)
    # 点击量
    clicknum = models.IntegerField(default=0)
    # 购买量
    buynum = models.IntegerField(default=0)

    class Meta:
        db_table = 'goods'



#购物车
class Cart(models.Model):
    # 用户id
    uid = models.ForeignKey(to=users)
    # 商品id
    goodsid = models.ForeignKey(to=goods)
    # 商品数量
    num = models.IntegerField()


    class Meta:
        db_table = 'cart'


# 城市数据
class Citys(models.Model):
    name = models.CharField(max_length=50)
    level = models.IntegerField()
    upid = models.IntegerField()


# 收货地址模型
class Address(models.Model):
    uid = models.ForeignKey(to="users")
    buser = models.CharField(max_length=50)
    buser_phone = models.CharField(max_length=11)
    province = models.IntegerField()
    city = models.IntegerField()
    county = models.IntegerField()
    info = models.CharField(max_length=100)
    isChecked = models.BooleanField(default=False)


# 订单
class Order(models.Model):
    uid = models.ForeignKey(to="users")
    # 收货人
    buser = models.CharField(max_length=50)
    # 收货电话
    buser_phone = models.CharField(max_length=11)
    # 收货地址
    re_addr = models.CharField(max_length=100)
    # 支付方式
    payment = models.CharField(max_length=10)
    # 物流方式
    logistics = models.CharField(max_length=10)
    # 订单总价
    totalprice = models.FloatField()
    # 创建时间
    addtime = models.DateTimeField(auto_now_add=True)
    # 支付时间
    buytime = models.DateTimeField(null=True)
    # 订单状态 0 新订单  1 已支付  2,已发货  3,已收货
    status = models.IntegerField(default=0)


    class Meta:
        db_table = 'order'

# 订单详情
class OrderInfo(models.Model):
    # 订单号
    orderid = models.ForeignKey(to="Order")
    # 商平id
    goodsid = models.IntegerField()
    # 商品名
    name = models.CharField(max_length=255)
    # 商品价格
    price = models.FloatField()

    pic_url = models.CharField(max_length=100)
    # 购买数量
    num = models.IntegerField()

    class Meta:
        db_table = 'orderinfo'



